package com.czkt.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.czkt.entity.SysRole;
import com.czkt.entity.SysUser;
import com.czkt.entity.vo.UserRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2024-06-18
 */
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {
    @Select("select * from crm.sys_user u,crm.sys_role r where u.usr_role_id=r.role_id and u.usr_name = #{usrName} and u.usr_password = #{usrPassword}")
    UserRole selectSysUser(@Param("usrName") String usrName, @Param("usrPassword") String usrPassword);

    @Select("select * from crm.sys_user u,crm.sys_role r where u.usr_role_id=r.role_id and u.usr_name = #{usrName}")
    UserRole selectRoleUser(@Param("usrName") String usrName);

    @Select("select * from crm.sys_user u where u.usr_id = #{usrId}")
    UserRole selectUsrId(String usrId);

    @Select("update crm.sys_user set usr_role_id = #{usrRoleId}, usr_name = #{usrName}, usr_password = #{usrPassword}, usr_flag = #{usrFlag} where usr_id = #{usrId}")
    void toUpdateUser(SysUser sysUser);

    @Select("delete from crm.sys_user where crm.sys_user.usr_id = #{usrId};")
    void deleteByUsrId(String usrId);

    @Select("insert into crm.sys_user (usr_name, usr_password, usr_role_id, usr_flag) values (#{usrName},#{usrPassword},#{usrRoleId},#{usrFlag})")
    void toInsertUser(SysUser sysUser);

    IPage<UserRole> selectUserAndRole(IPage<UserRole> userRoleIPage,@Param("usrName") String usrName, @Param("roleId") Long roleId);



}
